package com.weishi.project.training.controller;

import java.util.Date;
import java.util.List;

import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import java.util.Arrays;
import com.weishi.project.training.domain.NaturalYear;
import com.weishi.project.training.service.INaturalYearService;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.web.page.TableDataInfo;

/**
 * NaturalYearController
 */
@Api(value = "自然年",description = "自然年")
@RestController
@RequestMapping("/training/naturalYear")
public class NaturalYearController extends BaseController {

    @Autowired
    private INaturalYearService naturalYearService;

    /**
     * 查询自然年列表
     */
    @PreAuthorize("@ss.hasPermi('training:naturalYear:list')")
    @GetMapping("/list")
    public TableDataInfo list(NaturalYear naturalYear) {
        startPage();
        List<NaturalYear> list = naturalYearService.selectNaturalYearList(naturalYear);
        return getDataTable(list);
    }

    /**
     * 导出自然年列表
     */
    @PreAuthorize("@ss.hasPermi('training:naturalYear:export')")
    @Log(title = "NaturalYear", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(NaturalYear naturalYear) {
        List<NaturalYear> list = naturalYearService.selectNaturalYearList(naturalYear);
        ExcelUtil<NaturalYear> util = new ExcelUtil<NaturalYear>(NaturalYear.class);
        return util.exportExcel(list, "naturalYear");
    }

    /**
     * 获取自然年详细信息
     */
    @PreAuthorize("@ss.hasPermi('training:naturalYear:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(naturalYearService.getById(id));
    }

    /**
     * 新增自然年
     */
    @PreAuthorize("@ss.hasPermi('training:naturalYear:add')")
    @Log(title = "NaturalYear", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NaturalYear naturalYear) {
        naturalYear.setCtime(new Date());
        naturalYearService.save(naturalYear);
        return AjaxResult.success();
    }

    /**
     * 修改自然年
     */
    @PreAuthorize("@ss.hasPermi('training:naturalYear:edit')")
    @Log(title = "NaturalYear", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NaturalYear naturalYear) {
        naturalYearService.updateById(naturalYear);
        return AjaxResult.success();
    }

    /**
     * 删除自然年
     */
    @PreAuthorize("@ss.hasPermi('training:naturalYear:remove')")
    @Log(title = "NaturalYear", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        naturalYearService.removeYearAndWeek(ids);
        return AjaxResult.success();
    }

    /**
     * 查询自然年份集合
     */
    @PreAuthorize("@ss.hasPermi('training:naturalYear:list')")
    @GetMapping("/queryNaturalYearList")
    public TableDataInfo getAnnualPlanList() {
        startPage();
        List<NaturalYear> list = naturalYearService.getNaturalYearList();
        return getDataTable(list);
    }
    
}